<?php

if (!defined('SMF'))
	die('Hacking attempt...');

function SN_Ajax()
{
	global $context, $modSettings, $sourcedir, $db_show_debug;
	
			
	$embedder_check = (file_exists($sourcedir . '/AutoEmbedMediaPro2.php') || (file_exists($sourcedir . '/Aeva-Subs.php') && $modSettings['aeva_enable'] == 1));	
	
	// Available types of status updates.
	$context['status_update_types'] = array();
	if(!empty($modSettings['snet_enable_text'])) $context['status_update_types'][1] = 'text';
	if(!empty($modSettings['snet_enable_photo'])) $context['status_update_types'][2] = 'photo';
	if(!empty($modSettings['snet_enable_link'])) $context['status_update_types'][3] = 'link';
	if(!empty($modSettings['snet_enable_quote'])) $context['status_update_types'][4] = 'quote';
	if(!empty($modSettings['snet_enable_video']) && $embedder_check)
		$context['status_update_types'][5] = 'video';	
	
	$db_show_debug = false;
	
	loadTemplate('snet/SN-Ajax');
	loadLanguage('SimpleNetwork');

	require_once($sourcedir . '/snet/Subs-SimpleNetwork.php');
	
	$sub_actions = array(
		'postcomment' => array(
			'function' => 'SnetAjax_PostComment',
		),		
		'deletestatus' => array(
			'function' => 'SnetAjax_DeleteStatus',
		),
		'deletecomment' => array(
			'function' => 'SnetAjax_DeleteComment',
		),			
		'poststatus' => array(
			'function' => 'SnetAjax_PostStatusUpdate',
		),
		'likecomment' => array(
			'function' => 'SnetAjax_LikeComment',
		),		
		'dislikecomment' => array(
			'function' => 'SnetAjax_DislikeComment',
		),		
		'likestatus' => array(
			'function' => 'SnetAjax_LikeStatus',
		),		
		'dislikestatus' => array(
			'function' => 'SnetAjax_DislikeStatus',
		),			
		'loadcomments' => array(
			'function' => 'SnetAjax_LoadComments',
		),			
	);
	if (!isset($_REQUEST['sa'], $sub_actions[$_REQUEST['sa']]))
		fatal_lang_error('no_access', false);

	$sub_actions[$_REQUEST['sa']]['function']();
}

function SnetAjax_LoadComments()
{
	global $context, $scripturl, $modSettings, $settings, $txt, $user_info;
	
	$limit = !empty($_POST['limit']) ? (int) $_POST['limit'] : '';
	$start = !empty($_POST['start']) ? (int) $_POST['start'] : '';
	
	$context['canonical_url'] = $scripturl . '?action=profile;u=' . $_POST['profile'];
	$comments = snet_load_comments($_POST['status'],$limit,$start,!empty($_POST['single_view']) ? $_POST['single_view'] : false);
	$num_comments = count($comments);
	$cur_comment = 1;
	
	// Oh holy cookie, now we need to displat all of them.
	$context['return'] = '';
	foreach($comments AS $comment)
	{
		$cur_comment++;
		$comment_body = '<div id="comment' . $comment['id'] .'" class="snet_comment'.(($cur_comment > $num_comments-1) ? ' snet_bottom_comment' : '').'" style="display: none;">
						<div class="snet_poster_avatar_comment floatleft">
							<a href="'. $comment['user']['href']. '" title="' .$txt['profile_of']. ' '. $comment['user']['name']. '">'.$comment['user']['avatar']['image'].'</a><br />
						</div>

						<div class="snet_comment_content" >
							<div class="snet_comment_body">
								<a href="'. $comment['delete']. '" onclick="return snet_delete_comment(' . $comment['id'] .','.$_POST['status'].',' . JavaScriptEscape($txt['snet_confirm_delete_comment']). ');" id="snet_delete_comment_' . $comment['id'] .'" class="snet_delete" title="'. $txt['delete'] .'"><img src="'. $settings['default_images_url']. '/simplenetwork/delete.png" alt="'. $txt['delete'] .'" class="floatright" width="12px;" /></a>
								<strong>' . $comment['user']['link'] .'</strong><br />
								<span class="smalltext">'. $comment['body']. '</span>
							</div>				
						<div class="snet_status_actions smalltext">
							<span title="' . $comment['id']['real_date'] .'" id="d_' . $comment['timestamp'] .'" class="snet_date">' . $comment['date'] .'</span>
							<div class="snet_comment_likes">';
							
						if($modSettings['snet_enable_dislike_buttons'] != 0 && !empty($modSettings['snet_enable_dislike_buttons_comments']))
						$comment_body .= '
							<a href="' . $comment['dislike'] .'" onclick="return snet_dislike_comment(' . $comment['id'] .','.$user_info['id'].');" title="'.$txt['snet_comment_dislike'].'"><img src="'. $settings['default_images_url']. '/simplenetwork/dislike.png" class="snet_comment_dislike_icon" alt="Dislike" /></a><a href="#comment_dislikers_' . $comment['id'] .'" onclick="return snet_popup(\'comment_dislikers_' . $comment['id'] .'\');" class="snet_num_dislikes" id="snet_num_dislikers' . $comment['id'] .'">0</a>&nbsp;';
							
						if(!empty($modSettings['snet_enable_like_buttons']) && !empty($modSettings['snet_enable_like_buttons_comments']))
						$comment_body .= '
							<a href="' . $comment['like'] .'" onclick="return snet_like_comment(' . $comment['id'] .','.$user_info['id'].');" title="'.$txt['snet_comment_like'].'"><img src="'. $settings['default_images_url']. '/simplenetwork/like.png" class="snet_comment_like_icon" alt="Like" /></a><a href="#comment_dislikers_' . $comment['id'] .'" class="snet_num_likes" id="snet_num_likers' . $comment['id'] .'">0</a>&nbsp;';
					$comment_body .= '
							</div>	
							</div>
						</div>
						<hr />
						</div>';
						
						
		$context['return'] .= $comment_body;
	}	
	
	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';	
}

function SnetAjax_LikeStatus()
{
	global $context, $txt;
	
	$_POST['status'] = 373;
	$_POST['profile'] = 1;
	
	snet_like_status_update($_POST['status'],$_POST['profile']);

	$likers = snet_fetch_likers($_POST['status']);
	
	$num_total = count($likers);
	$num_grabbed = 1;
	$shown_likers = array();
	$likers_body = '';
	// Grab the ones we're gonna show, max 3.
	if($num_total != 0)
	{
		foreach($likers AS $liker)
		{
			if($num_grabbed <= 3)
				$shown_likers[] = $liker['member']['link'];

			$num_grabbed++;
		}
				
		// Display them nicely.
		if (count($shown_likers) <= 2)
			$likers_body .= implode(' ' . $txt['snet_and'] . ' ', $shown_likers);
		else
		{
			$last_peep = array_pop($shown_likers);
			$likers_body .= implode(', ' . $shown_likers). ''.(($num_total==3) ? ' ' . $txt['snet_and'] . ' ' : ', ').''. $last_peep;
		}
				
		if($num_total > 3)
		$likers_body .= $num_total == 4 ? sprintf($txt['snet_more_likers_single'],$_POST['status']) : sprintf($txt['snet_more_likers_multiple'],$_POST['status'],($num_total-3));

		$likers_body .= $num_total == 1 ? $txt['snet_likes_this'] : $txt['snet_like_this'];
	}
	else
		$likers_body = '0';

	$context['return'] = $likers_body;
	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

function SnetAjax_DislikeStatus()
{
	global $context, $modSettings, $txt;

	snet_dislike_status_update($_POST['status'],$_POST['profile']);

	$dislikers = snet_fetch_dislikers($_POST['status']);
	$dislikers_body = '';
	$num_total = count($dislikers);
	// Grab the ones we're gonna show, max 3.
	if($num_total != 0)
	{	
		// Are we showing names at all?
		if($modSettings['snet_enable_dislike_buttons'] == 1)
		{
			$num_grabbed = 1;
			$shown_dislikers = array();
			// Grab the ones we're gonna show, max 3.
			foreach($dislikers AS $disliker)
			{
				if($num_grabbed <= 3)
					$shown_dislikers[] = $disliker['member']['link'];
	
				$num_grabbed++;
			}
				
			// Display them nicely.
			if (count($shown_dislikers) <= 2)
				$dislikers_body .= implode(' ' . $txt['snet_and'] . ' ', $shown_dislikers);
			else
			{
				$last_peep = array_pop($shown_dislikers);
				$dislikers_body .= implode(', '. $shown_dislikers). ''.($num_total==3) ? ' ' . $txt['snet_and'] . ' ' : ', '.''. $last_peep;
			}
				
			if($num_total > 3)
			$dislikers_body .= $num_total == 4 ? sprintf($txt['snet_more_likers_single'],$status['id']) : sprintf($txt['snet_more_likers_multiple'],$status['id'],($num_total-3));

			$dislikers_body .= $num_total == 1 ? $txt['snet_dislikes_this'] : $txt['snet_dislike_this'];
		}
		else
		{
			$dislikers_body .= $num_total;
			$dislikers_body .= $num_total == 1 ? $txt['snet_anonymous_dislikes_single'] : $txt['snet_anonymous_dislikes_multiple'];		
		}
	}
	else
		$dislikers_body = '0';

	$context['return'] = $dislikers_body;
	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

function SnetAjax_LikeComment()
{
	global $context;
	
	snet_like_comment($_POST['comment'],$_POST['profile']);

	$context['return'] = 'true';
	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

function SnetAjax_DislikeComment()
{
	global $context;
	
	snet_dislike_comment($_POST['comment'],$_POST['profile']);

	$context['return'] = 'true';
	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

// Post a status update.
function SnetAjax_PostStatusUpdate()
{
	global $context, $sourcedir, $smcFunc, $modSettings, $user_info, $txt, $settings, $scripturl, $post_data;
	
	require_once($sourcedir . '/Subs-Editor.php');
	require_once($sourcedir . '/Subs-Post.php');
	require_once($sourcedir . '/snet/Subs-SimpleNetwork-Post.php');	
	
	// Validate it. Quite simple.
	$post_data = array();
	snet_process_post($_REQUEST['type'],$_REQUEST['profile']);
	
	if(!empty($context['snet_errors']))
		$context['return'] = 'snet_error_' . $txt['snet_error_' . $context['snet_errors'][0]];
	else
	{
		$new_status_id = snet_post_status_update($post_data,$_REQUEST['profile'],false,true);	
		
		// We'll want their avatar, blue or not.
		$request = $smcFunc['db_query']('','
			SELECT IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type, mem.avatar
			FROM {db_prefix}members AS mem
				LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
			WHERE mem.id_member = {int:user}',
			array(
				'user' => $user_info['id'],
			)
		);
	
		$avatar_row = $smcFunc['db_fetch_row']($request);
		$avatar = $avatar_row[3] == '' ? ($avatar_row[0] > 0 ? '<img class="avatar" src="' . (empty($avatar_row[2]) ? $scripturl . '?action=dlattach;attach=' . $avatar_row[0] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $avatar_row[1]) . '" alt="" />' : '') : (stristr($avatar_row[3], 'http://') ? '<img class="avatar" src="' . $avatar_row[3] . '" alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($avatar_row[3]) . '" alt="" />');
	
		$context['canonical_url'] = $scripturl . '?action=profile;u=' . $_REQUEST['profile'];
		
		$post_body = '<div id="status'. $new_status_id .'" class="snet_status" style="display: none;">
		<div class="windowbg'.($_REQUEST['altbg'] == true ? 2 : '').'">
				<span class="topslice"><span></span></span>
				<div class="content">
					<div class="snet_poster_avatar floatleft">
						<a href="' . $scripturl . '?action=profile;u=' . $user_info['id'] . '" title="' .$txt['profile_of']. ' ' . $user_info['name'] . '">'.$avatar.'</a><br />
						<a title="'. $txt['snet_status_type_' . $context['status_update_types'][$post_data['type']]]. '"><img src="'.$settings['default_images_url'].'/simplenetwork/' . $context['status_update_types'][$post_data['type']]. '.png" alt="'. $txt['snet_status_type_' . $context['status_update_types'][$post_data['type']]]. '" class="snet_post_type_icon" /></a>
					</div>
					<div class="snet_status_content">
					<div class="snet_status_body">
							<a href="'.$scripturl . '?action=profile;u=' . $_REQUEST['profile']. ';sa=delete;status='. $new_status_id .'" onclick="return snet_delete_update('. $new_status_id .',' . JavaScriptEscape($txt['snet_confirm_delete_status_update']). ');" id="snet_delete_'.$new_status_id.'" class="snet_delete" title="'.$txt['snet_delete'].'"><img src="'. $settings['default_images_url']. '/simplenetwork/delete.png" alt="'.$txt['snet_delete'].'" class="floatright" /></a>
							<strong><a href="' . $scripturl . '?action=profile;u=' . $user_info['id'] . '">' . $user_info['name'] . '</a></strong>
							<span class="smalltext">
								'.snet_parse_status_update($post_data['body'],$post_data['type']).'
							</span>
						</div>
						<hr/>
						<div class="snet_status_actions smalltext">
						<span title="'. timeformat(mktime()) .'" id="d_' . mktime() . '" class="snet_date">' . snet_relative_time(mktime()).'</span>
							| <a href="'.$context['canonical_url'].';status=' . $new_status_id . ';sa=view#comment" onclick="return snet_toggle_comment_form('. $new_status_id. ');">'.$txt['snet_comment'].'</a>';
						
					if($modSettings['snet_enable_dislike_buttons'] != 0)
						$post_body .= '
							<span id="snet_dislike_button_' . $new_status_id . '"> | <a href="'.$context['canonical_url'].';status=' . $new_status_id . ';sa=dislike" onclick="return snet_dislike_status_update(' . $new_status_id . ','.$_POST['profile'].',0);">'.$txt['snet_dislike'].'</a></span>';

					if(!empty($modSettings['snet_enable_like_buttons']))
						$post_body .= '
							<span id="snet_like_button_' . $new_status_id . '"> | <a href="'.$context['canonical_url'].';status=' . $new_status_id . ';sa=like" onclick="return snet_like_status_update(' . $new_status_id . ','.$_POST['profile'].',0);">'.$txt['snet_like'].'</a></span>';							

							
		$post_body .= '
					</div>
					<div class="description snet_likers" style="display: none;" id="snet_likers_container_' . $new_status_id . '">
						<img src="'. $settings['default_images_url']. '/simplenetwork/like.png" alt="" class="floatleft" />
						<span id="snet_likers_' . $new_status_id . '">
						</span>
					</div>
					<div class="description snet_dislikers" style="display: none;" id="snet_dislikers_container_' . $new_status_id . '">
						<img src="'. $settings['default_images_url']. '/simplenetwork/dislike.png" alt="" class="floatleft" />
						<span id="snet_dislikers_' . $new_status_id . '">
						</span>
					</div>					
					<div class="description snet_comments" id="comments' . $new_status_id . '" style="display: none;">
					</div>
					<div id="snet_status_comment_' . $new_status_id . '" style="display: none;" class="description snet_comments">
					<div class="errorbox" style="display: none;" id="snet_comment_errors_' . $new_status_id . '">
						<ul class="reset" id="snet_comment_errors_ul_' . $new_status_id . '">
						</ul>
					</div>
						<div class="snet_poster_avatar_comment floatleft">
							'.$avatar.'
						</div>
						<div class="snet_comment_content">
							<form action="'.$context['canonical_url'].';status=' . $new_status_id . ';sa=comment" method="post" class="snet_comment_body" onsubmit="return snet_post_comment(' . $new_status_id . ',' . $_REQUEST['profile'] . ');">
									<strong><a href="#">' . $user_info['name'] . '</a></strong><br />
									<span class="smalltext">
										<textarea cols="50" rows="2" name="snet_comment' . $new_status_id . '" id="snet_comment_field_' . $new_status_id . '"></textarea><br /><br />
										<input type="submit" value="'.$txt['snet_post_comment'].'" id="snet_comment_submit_' . $new_status_id . '" />
										<input type="hidden" name="'. $context['session_var']. '" value="'. $context['session_id']. '" />
									</span>
								</form>
							</div>
							<hr />
						</div>
					</div>
					<br class="clear" />	
				</div>
				<span class="botslice"><span></span></span>					
			</div>
			</div>';					
	
		$context['return'] = $post_body;
	}

	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

// Post a comment
function SnetAjax_PostComment()
{
	global $context, $sourcedir, $smcFunc, $modSettings, $user_info, $txt, $settings, $scripturl;
	
	require_once($sourcedir . '/Subs-Editor.php');
	require_once($sourcedir . '/Subs-Post.php');
	require_once($sourcedir . '/snet/Subs-SimpleNetwork-Post.php');	
	
	// Check the content of the comment body.
	if (!isset($_POST['snet_comment']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['snet_comment']), ENT_QUOTES) === '')
		$error = 'empty_comment';
	else
	{
		
		// More checkin'
		$_POST['snet_comment'] = $smcFunc['htmlspecialchars']($_POST['snet_comment'], ENT_QUOTES);
		preparsecode($_POST['snet_comment']);
		if ($smcFunc['htmltrim'](strip_tags(snet_format_text($_POST['snet_comment'], false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($_POST['snet_comment'], '[html]') === false))
			$error = 'empty_comment';
		elseif (!empty($modSettings['snet_max_comment_length']) && $smcFunc['strlen']($_POST['snet_comment']) > $modSettings['snet_max_comment_length'])
		{
			$error = 'long_comment';
			$txt['snet_error_long_comment'] = sprintf($txt['snet_error_long_comment'], $modSettings['snet_max_comment_length']);
		}
	}
	
	if(!empty($error))
		$context['return'] = 'snet_error_' . $txt['snet_error_' .$error];
	else
	{
		// Grab the ID of whoever posted this status update in the first place.
		$request = $smcFunc['db_query']('','
			SELECT id_user
			FROM {db_prefix}snet_status_updates
			WHERE id_status = {int:status}
			LIMIT 1',
			array(
				'status' => (int) $_REQUEST['status'],	
			)
		);
		list($status_owner) = $smcFunc['db_fetch_row']($request);
		$smcFunc['db_free_result']($request);	

		// Post a note to their wall!
		$id_note = snet_post_status_update(array(
			'body' => @serialize(array('body' => $status_owner != $_REQUEST['profile'] ? 'snet_note_posted_comment_wall_post' : 'snet_note_posted_comment', 'note_type' => 'comment', 'replacements' => array('{user}' => $status_owner, '{username}' => 'snet_fetch_username(' . $status_owner . ');', '{status}' => $_REQUEST['status']), 'evalrepl' => array('{username}'))),
			'type' => 6,
		),$_REQUEST['profile'],false,true);
		
		$comment_date = mktime();
		
		// Just put it into the database already...
		$smcFunc['db_insert']('',
			'{db_prefix}snet_comments',
			array(
				'id_status' => 'int', 'id_user' => 'int', 'id_note' => 'int', 'date' => 'int', 'body' => 'string',
			),
			array(
				$_REQUEST['status'], $user_info['id'], $id_note, $comment_date, $_POST['snet_comment'],
			),			
			array('id_comment')
		);			
		
		$id_comment = $smcFunc['db_insert_id']('{db_prefix}snet_comments', 'id_comment');
		
		// We'll want their avatar, blue or not.
		$request = $smcFunc['db_query']('','
			SELECT IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type, mem.avatar
			FROM {db_prefix}members AS mem
				LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
			WHERE mem.id_member = {int:user}',
			array(
				'user' => $user_info['id'],
			)
		);
		$avatar_row = $smcFunc['db_fetch_row']($request);
		$avatar = $avatar_row[3] == '' ? ($avatar_row[0] > 0 ? '<img class="avatar" src="' . (empty($avatar_row[2]) ? $scripturl . '?action=dlattach;attach=' . $avatar_row[0] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $avatar_row[1]) . '" alt="" />' : '') : (stristr($avatar_row[3], 'http://') ? '<img class="avatar" src="' . $avatar_row[3] . '" alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($avatar_row[3]) . '" alt="" />');

		if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
		{
			$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
			$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
		}
		else
		{
			$avatar_width = '';
			$avatar_height = '';
		}		
			
		$context['canonical_url'] = $scripturl . '?action=profile;u=' . $_REQUEST['profile'];
		
		$comment_body = '<div id="comment' . $id_comment .'" class="snet_comment" style="display: none;">
						<div class="snet_poster_avatar_comment floatleft">
							<a href="'.$scripturl.'?action=profile;u='.$user_info['id'].'" title="' .$txt['profile_of']. ' '. $user_info['name']. '">'.$avatar.'</a><br />
						</div>

						<div class="snet_comment_content" >
							<div class="snet_comment_body">
								<a href="'.$scripturl . '?action=profile;u=' . $_REQUEST['profile']. ';sa=deletecomment;status='.$_REQUEST['status'].';comment='.$id_comment.'" onclick="return snet_delete_comment('.$id_comment.','.$_POST['status'].',' . JavaScriptEscape($txt['snet_confirm_delete_comment']). ');" id="snet_delete_comment_'.$id_comment.'" class="snet_delete" title="'. $txt['delete'] .'"><img src="'. $settings['default_images_url']. '/simplenetwork/delete.png" alt="'. $txt['delete'] .'" class="floatright" width="12px;" /></a>
								<strong><a href="'.$scripturl.'?action=profile;u='.$user_info['id'].'">'.$user_info['name'].'</a></strong><br />
								<span class="smalltext">'.snet_format_text($_POST['snet_comment']).'</span>
							</div>				
						<div class="snet_status_actions smalltext">
							<span title="'. timeformat($comment_date,false) .'" id="d_'.$comment_date.'" class="snet_date">'. snet_relative_time($comment_date).'</span>
							<div class="snet_comment_likes">';
							
						if($modSettings['snet_enable_dislike_buttons'] != 0 && !empty($modSettings['snet_enable_dislike_buttons_comments']))
						$comment_body .= '
							<a href="' . $context['canonical_url'] . ';sa=dislikecomment;status=' . $_REQUEST['status'] . ';comment=' . $id_comment. '" onclick="return snet_dislike_comment(' . $id_comment.','.$user_info['id'].');" title="'.$txt['snet_comment_dislike'].'"><img src="'. $settings['default_images_url']. '/simplenetwork/dislike.png" class="snet_comment_dislike_icon" alt="Dislike" /></a><a href="#comment_dislikers_'. $id_comment .'" onclick="return snet_popup(\'comment_dislikers_'. $id_comment .'\');" class="snet_num_dislikes" id="snet_num_dislikers'.$id_comment.'">0</a>&nbsp;';
							
						if(!empty($modSettings['snet_enable_like_buttons']) && !empty($modSettings['snet_enable_like_buttons_comments']))
						$comment_body .= '
							<a href="' . $context['canonical_url'] . ';sa=likecomment;status=' . $_REQUEST['status'] . ';comment=' . $id_comment. '" onclick="return snet_like_comment(' . $id_comment.','.$user_info['id'].');" title="'.$txt['snet_comment_like'].'"><img src="'. $settings['default_images_url']. '/simplenetwork/like.png" class="snet_comment_like_icon" alt="Like" /></a><a href="#comment_dislikers_'. $id_comment .'" class="snet_num_likes" id="snet_num_likers'.$id_comment.'">0</a>&nbsp;';
					$comment_body .= '
							</div>	
							</div>
						</div>
						<hr />
						</div>';
						
						
		$context['return'] = $comment_body;
	}	

	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

// Validate a link.
function SnetAjax_ValidateLink()
{
	global $context;

	$context['valid'] = snet_validate_url($_REQUEST['snet_link']);

	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_validate_link';
}

// Get the title of a link.
function SnetAjax_GetLinkTitle()
{
	global $context;
	
	$meta_tags = get_meta_tags($_POST['snet_link']);
	
	$context['return'] = $meta_tags['title'];
	if(empty($context['return']['title']))
	{
		if(!($data = file_get_contents($_POST['snet_link'])))
			$context['return'] = 'broken_link';
		if(preg_match("#<title>(.+)<\/title>#iU", $data, $t))
			$context['return'] = trim($t[1]);
		else
			$context['return'] = '';
	}	

	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_return';
}

// Delete a status update.
function SnetAjax_DeleteStatus()
{
	global $context;

	$context['return'] = snet_delete_status_update($_REQUEST['status'],0,true);

	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_delete';
}

// Delete a comment
function SnetAjax_DeleteComment()
{
	global $context;

	$context['return'] = snet_delete_comment($_REQUEST['comment'],0,true);

	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_delete';
}

// Validate a quote.
function SnetAjax_ValidateQuote()
{
	global $context, $smcFunc;



	$context['template_layers'] = array();
	$context['sub_template'] = 'snet_validate_link';
}

?>